﻿using Assets.Game.scripts.ui.models;
using Engine.Entities.Character;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Assets.Game.scripts.ui.controllers {

    [RequireComponent(typeof(CharacterItemRendererModel))]
    class CharacterItemRendererController : MonoBehaviour{

        public UISprite genderSprite;
        public UIWidget skillWidget;
        public UIWidget statWidget;
        public UILabel nameLabel;
        public UILabel surnameLabel;
        public UILabel strengthLabel;
        public UILabel agilityLabel;
        public UILabel charmLabel;
        public UILabel resistanceLabel;
        public UILabel intelligenceLabel;

        public void Start() {
            CharacterItemRendererModel model = this.GetComponent<CharacterItemRendererModel>();

            if (model != null) { 
                if(this.genderSprite!=null){
                    if (model.gender == GenderEnum.Female) {
                        this.genderSprite.spriteName = "gender-female";
                    } else if (model.gender == GenderEnum.Male) {
                        this.genderSprite.spriteName = "gender-male";
                    }
                }

                if (this.nameLabel != null) {
                    this.nameLabel.text = model.name;
                }

                if (this.surnameLabel != null) {
                    this.surnameLabel.text = model.surname;
                }

                if (this.strengthLabel != null) {
                    this.strengthLabel.text = model.data.model.Skills.GetValue(SkillsEnum.Strenght).ToString();
                }

                if (this.agilityLabel != null) {
                    this.agilityLabel.text = model.data.model.Skills.GetValue(SkillsEnum.Agility).ToString();
                }

                if (this.charmLabel != null) {
                    this.charmLabel.text = model.data.model.Skills.GetValue(SkillsEnum.Charm).ToString();
                }

                if (this.resistanceLabel != null) {
                    this.resistanceLabel.text = model.data.model.Skills.GetValue(SkillsEnum.Resistance).ToString();
                }

                if (this.intelligenceLabel != null) {
                    this.intelligenceLabel.text = model.data.model.Skills.GetValue(SkillsEnum.Intelligence).ToString();
                }
            }
        }


        public void onRotationTweenCompleted() {
            bool statusSkill = this.skillWidget.gameObject.activeSelf;
            bool statusStat = this.statWidget.gameObject.activeSelf;

            NGUITools.SetActive(this.skillWidget.gameObject, !statusSkill);
            NGUITools.SetActive(this.statWidget.gameObject, !statusStat);
        }
    }
}
